export const xhrSend=({
    timeout=60000,
    method,
    body,
    url,
    headers={}
}={},xhr)=>{
    return new Promise((resolve,reject)=>{
        xhr.onreadystatechange=function(){
            if(xhr.readyState!==4){
                return;
            }
            const res={
                status:xhr.status,
                //todo:kule 暂时只使用text
                body:xhr.responseText
            };
            if(xhr.status>=200&&xhr.status<300){
                resolve(res);
                return;
            }
            reject(res);
        };
        xhr.onerror=reject;
        xhr.timeout=timeout;
        // xhr.ontimeout=reject;
        xhr.open(method,url,true);
        for(let k in headers){
            xhr.setRequestHeader(k,headers[k]);
        }
        xhr.send(body);
    });
};
export default xhrSend;